package qingke.command;

import java.util.HashMap;
import java.util.Map;


import qingke.command.impl.CreateLable;
import qingke.command.impl.CreateMemorandum;
import qingke.command.impl.CutLable;
import qingke.command.impl.DeleteLable;
import qingke.command.impl.DeleteMemorandum;
import qingke.command.impl.FindByContent;
import qingke.command.impl.FindByLable;
import qingke.command.impl.FindByManyLable;
import qingke.command.impl.FindByTime;
import qingke.command.impl.FindByTitle;
import qingke.command.impl.ReviseLable;
import qingke.command.impl.UpdateLable;
import qingke.command.impl.UpdateMemorandum;
import qingke.command.CommandFactory.CommandCode;
import qingke.command.impl.AddLable1;


public class CommandFactory {
	public static enum CommandCode {
		AL,CL,CM,CUL,DL,DM,FBC,FBL,FBML,FBT,FBTI,RL,UL,UM
	}
	
private static Map<CommandCode,Class<? extends Command>> commandMap = new HashMap();	
	
	static {
		commandMap.put(CommandCode.AL, AddLable1.class);
		commandMap.put(CommandCode.CL, CreateLable.class);
		commandMap.put(CommandCode.CM, CreateMemorandum.class);
		commandMap.put(CommandCode.CUL, CutLable.class);
		commandMap.put(CommandCode.DL, DeleteLable.class);
		commandMap.put(CommandCode.DM, DeleteMemorandum.class);
		commandMap.put(CommandCode.FBC, FindByContent.class);
		commandMap.put(CommandCode.FBL, FindByLable.class);
		commandMap.put(CommandCode.FBML, FindByManyLable.class);
		commandMap.put(CommandCode.FBT, FindByTime.class);
		commandMap.put(CommandCode.FBTI, FindByTitle.class);
		commandMap.put(CommandCode.RL, ReviseLable.class);
		commandMap.put(CommandCode.UL, UpdateLable.class);
		commandMap.put(CommandCode.UM, UpdateMemorandum.class);
	}
	
	public static Command buildCommand(CommandCode code){
		Class<? extends Command> cmdClass = commandMap.get(code);
		if (cmdClass != null) {
			try {
				return cmdClass.newInstance();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return null;
		
	}
}
